package com.micro.utils;

import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.Properties;

/**
 * @author micro
 */
public class PropertyUtil {
    private static Properties properties = new Properties();

    public static void loadProperties(String path) throws IOException {
        try (FileInputStream fis = new FileInputStream(path)) {
            properties.load(fis);
        }
    }

    public static String readProperty(String key) {
        return properties.getProperty(key);
    }

    public static void saveProperty(String key, String value) {
        properties.setProperty(key, value);
    }

    public static void writeToFile(String path, String describe) throws IOException {
        FileOutputStream fileOutputStream = new FileOutputStream(path);
        properties.store(fileOutputStream, describe);
        fileOutputStream.close();
    }

    public static void main(String[] args) throws IOException {
        loadProperties("config.properties");
        writeToFile("config.properties", "我爱北京");
    }
}
